package com.magic.smartcity.view.more.viewmodels

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.magic.smartcity.beans.ParkBannerBean
import com.magic.smartcity.beans.ParkBean
import com.magic.smartcity.beans.ParkRecordBean
import com.magic.smartcity.view.more.models.ParkModel

/**
 * @description:
 * @create: Create by Magic on 2022/2/23.
 */
class ParkViewModel() : ViewModel() {
    private val TAG: String = "ParkViewModel"

    val parkBean: MutableLiveData<ParkBean> = MutableLiveData()
    val parkList: MutableLiveData<List<ParkBean>> = MutableLiveData()
    val parkRecordList: MutableLiveData<List<ParkRecordBean>> = MutableLiveData()
    val bannerList: MutableLiveData<List<ParkBannerBean>> = MutableLiveData()
    private val model = ParkModel()

    fun getParkList() {
        Log.d(TAG,"请求获取停车场列表")
        model.getParkList(success = {
            val list = it.sortedBy { it1 -> it1.distance }
            parkList.postValue(list)
        }, error = {})
    }

    fun getParkById(parkId: Int) {
        Log.d(TAG,"请求获取指定停车场${parkId}}")
        model.getParkById(parkId, success = {
            parkBean.postValue(it)
        }, error = {})
    }

    fun getParkRecordList() {
        Log.d(TAG,"请求获取停车历史记录列表")
        model.getParkRecord(success = {
            parkRecordList.postValue(it)
        }, error = {})
    }

    fun getBannerList() {
        Log.d(TAG,"请求获取首页轮播图")
        model.getBannerList(success = {
            bannerList.postValue(it)
        }, error = {})
    }

}